package zpin.action;

import java.util.List;

import util.dao.Pagination;
import zpin.dao.CityDao;
import zpin.dao.EngageDao;
import zpin.dao.TypeDao;
import zpin.model.City;
import zpin.model.Engage;
import zpin.model.Type;

import com.opensymphony.xwork2.ActionSupport;

public class AdminEngageAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	
	private Engage engage;
	
	private City city;
	
	private Type type;
	
	private EngageDao engageDao;
	
	private CityDao cityDao;
	
	private TypeDao typeDao;
	
	private List<Engage> engagelist;
	
	private Pagination<Engage> pagination;

	public Pagination<Engage> getPagination() {
		return pagination;
	}

	public void setPagination(Pagination<Engage> pagination) {
		this.pagination = pagination;
	}

	public Engage getEngage() {
		return engage;
	}

	public void setEngage(Engage engage) {
		this.engage = engage;
	}

	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public EngageDao getEngageDao() {
		return engageDao;
	}

	public void setEngageDao(EngageDao engageDao) {
		this.engageDao = engageDao;
	}

	public CityDao getCityDao() {
		return cityDao;
	}

	public void setCityDao(CityDao cityDao) {
		this.cityDao = cityDao;
	}

	public TypeDao getTypeDao() {
		return typeDao;
	}

	public void setTypeDao(TypeDao typeDao) {
		this.typeDao = typeDao;
	}

	public List<Engage> getEngagelist() {
		return engagelist;
	}

	public void setEngagelist(List<Engage> engagelist) {
		this.engagelist = engagelist;
	}
	
	public String show(){
		if (pagination == null) {
			this.pagination = new Pagination<Engage>();
		}

		if (this.pagination.getSize() == 0) {
			this.pagination.setSize(5);
		}
		if (this.pagination.getNo() == 0) {
			this.pagination.setNo(1);
		}
		engageDao.browse(pagination);
		engagelist = pagination.getResults();
		
		return SUCCESS;
	}
	
	public String delete(){
		engageDao.delete(engage);
		
		return SUCCESS;
	}
	
	public String detail(){
		this.engage = engageDao.findById(engage.getId());
		
		return SUCCESS;
	}
}
